package org.lee.hello;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.implementation.bytecode.assign.Assigner;

import static net.bytebuddy.matcher.ElementMatchers.named;

/**
 * @author jackielee
 * @version 1.0
 * @description Demo2
 * @date 2021/7/28
 **/
public class Demo2 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException {

        String res = new ByteBuddy()
                .subclass(Hello.class)
                .method(named("nice"))
                .intercept(FixedValue.argument(0).withAssigner(Assigner.DEFAULT, Assigner.Typing.valueOf("dralee")))
                .make()
                .load(Demo2.class.getClassLoader())
                .getLoaded()
                .newInstance()
                .nice("");
        System.out.println(res);
    }


    public class Hello {
        public String nice(String name) {
            return "nice to meet " + name;
        }
    }
}
